package com.learning.spring.cloud.ms.consumer.movie.controller;

import com.google.common.collect.Maps;
import com.learning.spring.cloud.ms.consumer.movie.entity.User;
import com.learning.spring.cloud.ms.consumer.movie.feign.UserFeignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * ClassName: MovieController
 * Description:
 * Date: 2019/5/31 10:42 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
@Slf4j
@RestController
@RequestMapping("movie")
public class MovieController {


    @Autowired
    private UserFeignService userFeignService;

    /**
     * http://localhost:8010/movie/user/1
     *
     * @param id
     * @return
     */
    @GetMapping("/user/{id}")
    public User findById(@PathVariable Long id) {
        return userFeignService.findById(id);
    }


    /**
     * 测试URL：http://localhost:8010/movie/user/get?id=1&username=张三
     * 该请求不会成功。
     *
     * @param user user
     * @return 用户信息
     */
    @GetMapping("/user/get")
    public User get(User user) {
        return userFeignService.get(user);
    }

    /**
     * 测试URL：http://localhost:8010/movie/user/getByParam?id=1&username=张三
     *
     * @param user user
     * @return 用户信息
     */
    @GetMapping("/user/getByParam")
    public User getByParam(User user) {
        return userFeignService.getByParam(user.getId(), user.getUsername());
    }

    /**
     * 测试URL：http://localhost:8010/movie/user/getByMap?id=1&username=张三
     *
     * @param user user
     * @return 用户信息
     */
    @GetMapping("/user/getByMap")
    public User getByMap(User user) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("id", user.getId());
        map.put("username", user.getUsername());
        return userFeignService.getByMap(map);
    }

    /**
     * 测试URL:http://localhost:8010/movie/user/post?id=1&username=张三
     *
     * @param user user
     * @return 用户信息
     */
    @GetMapping("/user/post")
    public User post(User user) {
        return userFeignService.post(user);
    }


}
